/*
 * $Id: ObjectTextForm.java 112 2009-07-01 11:33:10Z donbeave $
 */

package labour.manager.client.widget.form;

import labour.concept.client.data.Locale;
import labour.concept.client.data.ObjectText;

import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;

public class ObjectTextForm extends FormPanel {

  private ComboBox<Locale> localesBox;
  private TextField<String> nameField;

  public ObjectTextForm() {
    setHeading("Text Data");

    setFrame(true);

    localesBox = new ComboBox<Locale>();
    localesBox.setFieldLabel("Locale");
    localesBox.setDisplayField("Language");
    add(localesBox);

    nameField = new TextField<String>();
    nameField.setFieldLabel("Name");
    nameField.setAllowBlank(false);
    add(nameField);
  }

  public ObjectTextForm(ObjectText text) {
    this();

    setModel(text);
  }

  public ComboBox<Locale> getLocalesBox() {
    return localesBox;
  }

  public TextField<String> getNameField() {
    return nameField;
  }

  @Override
  @SuppressWarnings("unchecked")
  public ObjectText getModel() {
    return (ObjectText) super.getModel();
  }

  public void setModel(ObjectText item) {
    super.setModel(item);

    getNameField().setValue(item.getModel().getName());

    ListStore<Locale> locales = new ListStore<Locale>();
    locales.add(item.getManager().getLocales());

    getLocalesBox().setStore(locales);

    getLocalesBox().setValue(item.getLocale());
  }

}
